# -- coding: utf-8 --”
import pygame
from pygame.locals import *
import jiemian
import level1
import level10
import level2
import level3
import level4
import level5
import level6
import level7
import level8
import level9


class Jiemian:
    jiemian_music = None

    def __init__(self):
        W = 1400
        H = 800
        pygame.init()
        pygame.mixer.music.stop()
        pygame.display.set_caption("零零守护者")
        try:
            with open("data/窗口.txt", "r", encoding="utf-8") as f:
                text = f.read()
                f.close()
            print(text)
        except:
            text = ""
        if text == "全屏模式":
            window = pygame.display.set_mode((W, H), pygame.FULLSCREEN)
        else:
            window = pygame.display.set_mode((W, H))

        img = pygame.image.load("img/界面背景.png")  # 如果你要尝试，要么图片放在原位，要么改变路径
        Jiemian.jiemian_music = pygame.mixer.Sound("wav/游戏界面.mp3")  # 替换为你的音乐文件路径
        Jiemian.jiemian_music.play(-1)  # -1表示无限循环播放

        button_color1 = (45, 102, 78)
        button_color2 = (45, 102, 78)
        button_color3 = (45, 102, 78)
        button_color4 = (45, 102, 78)
        button_color5 = (45, 102, 78)
        button_color6 = (45, 102, 78)
        button_color7 = (45, 102, 78)
        button_color8 = (45, 102, 78)
        button_color9 = (45, 102, 78)
        button_color10 = (45, 102, 78)
        button_color11 = (45, 102, 78)
        button_color12 = (45, 102, 78)
        button_color13 = (45, 102, 78)
        button_color14 = (45, 102, 78)
        button_color15 = (45, 102, 78)

        # 按钮字体
        button_font2 = pygame.font.Font('font/datouren.ttf', 60)
        button_font = pygame.font.Font('font/datouren.ttf', 40)

        width1, height1 = 120, 120
        text_color1 = (0, 0, 0)

        x1, y1 = 220, 200
        button_rect1 = pygame.Rect(x1, y1, width1, height1)
        button_text1 = button_font2.render("1", True, text_color1)

        x2, y2 = 420, 200
        button_rect2 = pygame.Rect(x2, y2, width1, height1)
        button_text2 = button_font2.render("2", True, text_color1)

        x3, y3 = 620, 200
        button_rect3 = pygame.Rect(x3, y3, width1, height1)
        button_text3 = button_font2.render("3", True, text_color1)

        x4, y4 = 820, 200
        button_rect4 = pygame.Rect(x4, y4, width1, height1)
        button_text4 = button_font2.render("4", True, text_color1)

        x5, y5 = 1020, 200
        button_rect5 = pygame.Rect(x5, y5, width1, height1)
        button_text5 = button_font2.render("5", True, text_color1)

        x6, y6 = 220, 400
        button_rect6 = pygame.Rect(x6, y6, width1, height1)
        button_text6 = button_font2.render("6", True, text_color1)

        x7, y7 = 420, 400
        button_rect7 = pygame.Rect(x7, y7, width1, height1)
        button_text7 = button_font2.render("7", True, text_color1)

        x8, y8 = 620, 400
        button_rect8 = pygame.Rect(x8, y8, width1, height1)
        button_text8 = button_font2.render("8", True, text_color1)

        x9, y9 = 820, 400
        button_rect9 = pygame.Rect(x9, y9, width1, height1)
        button_text9 = button_font2.render("9", True, text_color1)

        x10, y10 = 1020, 400
        button_rect10 = pygame.Rect(x10, y10, width1, height1)
        button_text10 = button_font2.render("10", True, text_color1)

        # x11, y11 = 220, 500
        # button_rect11 = pygame.Rect(x11, y11, width1, height1)
        # button_text11 = button_font2.render("11", True, text_color1)
        #
        # x12, y12 = 420, 500
        # button_rect12 = pygame.Rect(x12, y12, width1, height1)
        # button_text12 = button_font2.render("12", True, text_color1)
        #
        # x13, y13 = 620, 500
        # button_rect13 = pygame.Rect(x13, y13, width1, height1)
        # button_text13 = button_font2.render("13", True, text_color1)
        #
        # x14, y14 = 820, 500
        # button_rect14 = pygame.Rect(x14, y14, width1, height1)
        # button_text14 = button_font2.render("14", True, text_color1)
        #
        # x15, y15 = 1020, 500
        # button_rect15 = pygame.Rect(x15, y15, width1, height1)
        # button_text15 = button_font2.render("15", True, text_color1)

        # 返回按钮
        x, y = 1280, 730
        width, height = 120, 70
        button_rect = pygame.Rect(x, y, width, height)
        button_color = (45, 102, 78)
        text_color = (0, 0, 0)
        button_text = button_font.render("返回", True, text_color)

        # 加载按钮声音
        button_sound = pygame.mixer.Sound("wav/跳.wav")  # 替换为你的音乐文件路径

        # 定义按钮状态
        button_pressed = False
        button_pressed1 = False
        button_pressed2 = False
        button_pressed3 = False
        button_pressed4 = False
        button_pressed5 = False
        button_pressed6 = False
        button_pressed7 = False
        button_pressed8 = False
        button_pressed9 = False
        button_pressed10 = False
        button_pressed11 = False
        button_pressed12 = False
        button_pressed13 = False
        button_pressed14 = False
        button_pressed15 = False

        try:
            with open("data/关卡数据.txt", "r", encoding="utf-8") as f:
                texts = f.readlines(10)
                text = texts[0]
                f.close()
            print(text)
        except:
            text = ""

        Fullscreen = False
        flag = True
        while flag:
            # 背景图刷新
            window.blit(img, (0, 1))
            # 绘制按钮
            # 开始按钮

            pygame.draw.rect(window, button_color, button_rect)
            window.blit(button_text, (button_rect.centerx - button_text.get_width()
                                      / 2, button_rect.centery - button_text.get_height() / 2))

            pygame.draw.rect(window, button_color1, button_rect1)
            window.blit(button_text1, (button_rect1.centerx - button_text1.get_width()
                                       / 2, button_rect1.centery - button_text1.get_height() / 2))

            pygame.draw.rect(window, button_color2, button_rect2)
            window.blit(button_text2, (button_rect2.centerx - button_text2.get_width()
                                       / 2, button_rect2.centery - button_text2.get_height() / 2))
            pygame.draw.rect(window, button_color3, button_rect3)
            window.blit(button_text3, (button_rect3.centerx - button_text3.get_width()
                                       / 2, button_rect3.centery - button_text3.get_height() / 2))
            pygame.draw.rect(window, button_color4, button_rect4)
            window.blit(button_text4, (button_rect4.centerx - button_text4.get_width()
                                       / 2, button_rect4.centery - button_text4.get_height() / 2))

            pygame.draw.rect(window, button_color5, button_rect5)
            window.blit(button_text5, (button_rect5.centerx - button_text5.get_width()
                                       / 2, button_rect5.centery - button_text5.get_height() / 2))
            pygame.draw.rect(window, button_color6, button_rect6)
            window.blit(button_text6, (button_rect6.centerx - button_text6.get_width()
                                       / 2, button_rect6.centery - button_text6.get_height() / 2))

            pygame.draw.rect(window, button_color7, button_rect7)
            window.blit(button_text7, (button_rect7.centerx - button_text7.get_width()
                                       / 2, button_rect7.centery - button_text7.get_height() / 2))

            pygame.draw.rect(window, button_color8, button_rect8)
            window.blit(button_text8, (button_rect8.centerx - button_text8.get_width()
                                       / 2, button_rect8.centery - button_text8.get_height() / 2))
            pygame.draw.rect(window, button_color9, button_rect9)
            window.blit(button_text9, (button_rect9.centerx - button_text9.get_width()
                                       / 2, button_rect9.centery - button_text9.get_height() / 2))

            pygame.draw.rect(window, button_color10, button_rect10)
            window.blit(button_text10, (button_rect10.centerx - button_text10.get_width()
                                        / 2, button_rect10.centery - button_text10.get_height() / 2))

            # pygame.draw.rect(window, button_color11, button_rect11)
            # window.blit(button_text11, (button_rect11.centerx - button_text11.get_width()
            #                             / 2, button_rect11.centery - button_text11.get_height() / 2))
            #
            # pygame.draw.rect(window, button_color12, button_rect12)
            # window.blit(button_text12, (button_rect12.centerx - button_text12.get_width()
            #                             / 2, button_rect12.centery - button_text12.get_height() / 2))
            #
            # pygame.draw.rect(window, button_color13, button_rect13)
            # window.blit(button_text13, (button_rect13.centerx - button_text13.get_width()
            #                             / 2, button_rect13.centery - button_text13.get_height() / 2))
            #
            # pygame.draw.rect(window, button_color14, button_rect14)
            # window.blit(button_text14, (button_rect14.centerx - button_text14.get_width()
            #                             / 2, button_rect14.centery - button_text14.get_height() / 2))
            #
            # pygame.draw.rect(window, button_color15, button_rect15)
            # window.blit(button_text15, (button_rect15.centerx - button_text15.get_width()
            #                             / 2, button_rect15.centery - button_text15.get_height() / 2))

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    exit()

                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_p:
                        Fullscreen = not Fullscreen
                        if Fullscreen:
                            window = pygame.display.set_mode((W, H), FULLSCREEN | HWSURFACE, 32)
                        else:
                            window = pygame.display.set_mode((W, H), 0, 32)

                # 点击按钮
                if event.type == pygame.MOUSEBUTTONDOWN:
                    if button_rect.collidepoint(event.pos):
                        # 在这里执行按钮点击后的操作
                        print("返回按钮")
                        button_color = (255, 255, 0)
                        button_pressed = True
                        button_sound.play()

                    if button_rect1.collidepoint(event.pos):
                        # 在这里执行按钮点击后的操作
                        print("1")
                        button_color1 = (255, 255, 0)
                        button_pressed1 = True
                        button_sound.play()

                    if button_rect2.collidepoint(event.pos):
                        # 在这里执行按钮点击后的操作
                        print("2")
                        button_color2 = (255, 255, 0)
                        button_pressed2 = True
                        button_sound.play()

                    if button_rect3.collidepoint(event.pos):
                        # 在这里执行按钮点击后的操作
                        print("3")
                        button_color3 = (255, 255, 0)
                        button_pressed3 = True
                        button_sound.play()

                    if button_rect4.collidepoint(event.pos):
                        # 在这里执行按钮点击后的操作
                        print("4")
                        button_color4 = (255, 255, 0)
                        button_pressed4 = True
                        button_sound.play()

                    if button_rect5.collidepoint(event.pos):
                        # 在这里执行按钮点击后的操作
                        print("5")
                        button_color5 = (255, 255, 0)
                        button_pressed5 = True
                        button_sound.play()

                    if button_rect6.collidepoint(event.pos):
                        # 在这里执行按钮点击后的操作
                        print("6")
                        button_color6 = (255, 255, 0)
                        button_pressed6 = True
                        button_sound.play()

                    if button_rect7.collidepoint(event.pos):
                        # 在这里执行按钮点击后的操作
                        print("7")
                        button_color7 = (255, 255, 0)
                        button_pressed7 = True
                        button_sound.play()

                    if button_rect8.collidepoint(event.pos):
                        # 在这里执行按钮点击后的操作
                        print("8")
                        button_color8 = (255, 255, 0)
                        button_pressed8 = True
                        button_sound.play()

                    if button_rect9.collidepoint(event.pos):
                        # 在这里执行按钮点击后的操作
                        print("9")
                        button_color9 = (255, 255, 0)
                        button_pressed9 = True
                        button_sound.play()

                    if button_rect10.collidepoint(event.pos):
                        # 在这里执行按钮点击后的操作
                        print("10")
                        button_color10 = (255, 255, 0)
                        button_pressed10 = True
                        button_sound.play()

                    # if button_rect11.collidepoint(event.pos):
                    #     # 在这里执行按钮点击后的操作
                    #     print("11")
                    #     button_color11 = (255, 255, 0)
                    #     button_pressed11 = True
                    #     button_sound.play()
                    #
                    # if button_rect12.collidepoint(event.pos):
                    #     # 在这里执行按钮点击后的操作
                    #     print("12")
                    #     button_color12 = (255, 255, 0)
                    #     button_pressed12 = True
                    #     button_sound.play()
                    #
                    # if button_rect13.collidepoint(event.pos):
                    #     # 在这里执行按钮点击后的操作
                    #     print("13")
                    #     button_color13 = (255, 255, 0)
                    #     button_pressed13 = True
                    #     button_sound.play()
                    #
                    # if button_rect14.collidepoint(event.pos):
                    #     # 在这里执行按钮点击后的操作
                    #     print("14")
                    #     button_color14 = (255, 255, 0)
                    #     button_pressed14 = True
                    #     button_sound.play()
                    #
                    # if button_rect15.collidepoint(event.pos):
                    #     # 在这里执行按钮点击后的操作
                    #     print("15")
                    #     button_color15 = (255, 255, 0)
                    #     button_pressed15 = True
                    #     button_sound.play()

                # 处理鼠标松开事件
                if event.type == pygame.MOUSEBUTTONUP:
                    if button_pressed:
                        button_color = (45, 102, 78)
                        button_pressed = False
                        Jiemian.jiemian_music.stop()
                        jiemian.Jiemian()
                        print("开始按钮松开了")

                    if button_pressed1:
                        Jiemian.jiemian_music.stop()
                        level1.Game().game_star()
                        button_color1 = (45, 102, 78)
                        button_pressed1 = False

                    if button_pressed2:
                        Jiemian.jiemian_music.stop()
                        level2.Game().game_star()
                        button_color2 = (45, 102, 78)
                        button_pressed2 = False

                    if button_pressed3:
                        Jiemian.jiemian_music.stop()
                        level3.Game().game_star()
                        button_color3 = (45, 102, 78)
                        button_pressed3 = False

                    if button_pressed4:
                        Jiemian.jiemian_music.stop()
                        level4.Game().game_star()
                        button_color4 = (45, 102, 78)
                        button_pressed4 = False

                    if button_pressed5:
                        Jiemian.jiemian_music.stop()
                        level5.Game().game_star()
                        button_color5 = (45, 102, 78)
                        button_pressed5 = False

                    if button_pressed6:
                        Jiemian.jiemian_music.stop()
                        level6.Game().game_star()
                        button_color6 = (45, 102, 78)
                        button_pressed6 = False


                    if button_pressed7:
                        Jiemian.jiemian_music.stop()
                        level7.Game().game_star()
                        button_color7 = (45, 102, 78)
                        button_pressed7 = False

                    if button_pressed8:
                        Jiemian.jiemian_music.stop()
                        level8.Game().game_star()
                        button_color8 = (45, 102, 78)
                        button_pressed8 = False

                    if button_pressed9:
                        Jiemian.jiemian_music.stop()
                        level9.Game().game_star()
                        button_color9 = (45, 102, 78)
                        button_pressed9 = False

                    if button_pressed10:
                        Jiemian.jiemian_music.stop()
                        level10.Game().game_star()
                        button_color10 = (45, 102, 78)
                        button_pressed10 = False

                    # if button_pressed11:
                    #     button_color11 = (45, 102, 78)
                    #     button_pressed11 = False
                    #
                    # if button_pressed12:
                    #     button_color12 = (45, 102, 78)
                    #     button_pressed12 = False
                    #
                    # if button_pressed13:
                    #     button_color13 = (45, 102, 78)
                    #     button_pressed13 = False
                    #
                    # if button_pressed14:
                    #     button_color14 = (45, 102, 78)
                    #     button_pressed14 = False
                    #
                    # if button_pressed15:
                    #     button_color15 = (45, 102, 78)
                    #     button_pressed15 = False

            pygame.display.flip()  # 更新屏幕显示


if __name__ == '__main__':
    Jiemian()
